<?php
/**
 * 2018-07-17
 * 
 * 刘家腾
 * 
 * class:QuestionController
 */
namespace App\Http\Controllers;

use App\Common\Base;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use App\Service\DataReturnService as DRS;
use Illuminate\Support\Facades\Validator;

class QuestionController extends Controller
{
    public function __construct() { }
    
   
     /**
     * 2018-7-18
     * 
     * 刘家腾
     * 
     * 常见问题 列表 基础SQL
     */
    public function list_sql()
    {
        DB::connection()->enableQueryLog();
        $list_data = DB::table('questions')
                ->select('id','title','create_time','update_time')
                ->where('state','=',0)
                ->orderBy('id','asc')
                ->paginate(20);
        DB::table('product'); // 要查看的sql
        $queries = \DB::getQueryLog(); // 获取查询日志
        
        return $list_data;
    }
    /**
     * 2018-7-18
     * 
     * 刘家腾
     * 
     * 常见问题 列表
     * 
     */
    public function list(Request $R)
    {
        $postData  = $R->all();
        if (! $R->filled('business_id')) {
            return DRS::returnError(3000,'缺少核心参数：business_id');
        }
        $searchData=self::list_sql();
        return DRS::returnOk($searchData);
    }
    /**
     * 2018-7-19
     * 
     * 刘家腾
     * 
     * 常见问题 基础SQL
     */
    public function info_sql($id='')
    {
        DB::connection()->enableQueryLog();
        $info_data = DB::table('questions')
                ->select('id','title','content','create_time','update_time')
                ->where('state','=',0)
                ->where('id','=',$id)
                ->orderBy('id','desc')
                ->get()->toarray();
        DB::table('product'); // 要查看的sql
        $queries = \DB::getQueryLog(); // 获取查询日志
        
        return array_map('get_object_vars', $info_data); 
    }
    /**
     * 2018-7-19
     * 
     * 刘家腾
     * 
     * 常见问题 
     */
    public function info(Request $R)
    {
        $postData  = $R->all();
        if (! $R->filled('business_id')) {
            return DRS::returnError(3000,'缺少核心参数：business_id');
        }
        if (! $R->filled('id')) {
            return DRS::returnError(3000,'缺少核心参数：id');
        }
        $searchData=self::info_sql($postData['id']);
        return DRS::returnOk($searchData);
    }


}